from django import template
import time
from datetime import datetime

register  = template.Library()

@register.filter(name='datetime')
def datetime_filter(t):
	delta = int(time.time() - t)
	if delta <60:
		return u'1分钟前'
	if delta <3600:
		return u'%s分钟前' % (delta // 60)
	if delta <24*3600:
		return u'%s小时钟前'% (delta //3600)
	if delta <12*24*3600:
		return u'%s天前' % (delta // 86400)

	dt = datetime.fromtimestamp(t)
	return u'%s 年%s月%s日' % (dt.year, dt.month. dt.day)
